﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Soapi.Domain;
using Soapi.Notify2.Lib;

namespace Soapi.Notify2
{
    /// <summary>
    /// We have an issue here - the act of setting our UserSettings object
    /// as the BindingSource.DataSource has side effects due to event bindings
    /// </summary>
    public partial class SettingsForm : Form
    {
        public SettingsForm()
        {

            InitializeComponent();
            Program.Settings.Save();
            userSettingsBindingSource.DataSource = Program.Settings;

        }

        private void GrowlLinkLabelLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start("http://www.growlforwindows.com/gfw/");
        }

        private void OkButton_Click(object sender, EventArgs e)
        {
            Program.Settings.Save();
            this.DialogResult = DialogResult.OK;
        }

        private void CancelButton_Click(object sender, EventArgs e)
        {
            // reset to incoming state.
            Program.Settings = new UserSettings();
            this.DialogResult = DialogResult.Cancel;
        }

        private void SelectAllSitesButton_Click(object sender, EventArgs e)
        {
            var sites = (IList<SiteListItem>)sitesBindingSource.List;
            foreach (SiteListItem site in sites)
            {
                site.Enabled = true;
            }
            SitesGridView.Refresh();
        }

        private void SelectNoneSitesButton_Click(object sender, EventArgs e)
        {
            var sites = (IList<SiteListItem>)sitesBindingSource.List;
            foreach (SiteListItem site in sites)
            {
                site.Enabled = false;
            }
            SitesGridView.Refresh();
        }

        private void SettingsForm_Load(object sender, EventArgs e)
        {
            if(PollingIntervalNumericUpDown.Value<10)
            {
                PollingIntervalNumericUpDown.Value = 10; // TODO: should validate, something odd is happening
            }
        }

    }
}
